package beans;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;
import javax.servlet.http.HttpServletRequest;

import org.hibernate.annotations.Type;

@Entity
public class Commentaire implements Serializable {

    @Transient
    private static final String ATT_USER_NAME   = "userName";
    @Transient
    private static final String ATT_USER_PRENOM = "userPrenom";

    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    private long                id;
    @Type(type="text")
    private String              text;
    private String              userName;
    private String              userPrenom;
    private Date                commentDate;

    public Commentaire()
    {

    }

    public Commentaire( String commentaire, HttpServletRequest request ) {
        this.text = commentaire;
        this.commentDate = new Date();
        this.userName = (String) request.getSession().getAttribute( ATT_USER_NAME );
        this.userPrenom = (String) request.getSession().getAttribute( ATT_USER_PRENOM );

    }

    // getters and setters
    // -------------------------------------------------------------
    // ---------------------------------------------------------------------------------

    public String getText() {
        return text;
    }

    public void setText( String text ) {
        this.text = text;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName( String userName ) {
        this.userName = userName;
    }

    public String getUserPrenom() {
        return userPrenom;
    }

    public void setUserPrenom( String userPrenom ) {
        this.userPrenom = userPrenom;
    }

    public Date getCommentDate() {
        return commentDate;
    }

    public void setCommentDate( Date commentDate ) {
        this.commentDate = commentDate;
    }

    public long getId() {
        return id;
    }

    public void setId( long id ) {
        this.id = id;
    }

}
